<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="喷头名称" prop="bottleSprayHeadNo">
      <el-input v-model="dataForm.bottleSprayHeadNo" placeholder="喷头名称"></el-input>
    </el-form-item>
    <el-form-item label="喷头规格" prop="spraySize">
      <el-input v-model="dataForm.spraySize" placeholder="喷头规格"></el-input>
    </el-form-item>
    <el-form-item label="规格描述" prop="sprayHeadDesc">
      <el-input v-model="dataForm.sprayHeadDesc" placeholder="规格描述"></el-input>
    </el-form-item>
    <el-form-item label="喷头类别" prop="sprayHeadType">
      <el-input v-model="dataForm.sprayHeadType" placeholder="喷头类别"></el-input>
    </el-form-item>
    <el-form-item label="喷头口径" prop="bottleOutDiameter">
      <el-input v-model="dataForm.bottleOutDiameter" placeholder="喷头口径"></el-input>
    </el-form-item>
    <el-form-item label="喷头颜色" prop="sprayHeadColor">
      <el-input v-model="dataForm.sprayHeadColor" placeholder="喷头颜色"></el-input>
    </el-form-item>
    <el-form-item label="喷头的材质" prop="sprayHeadMaterial">
      <el-input v-model="dataForm.sprayHeadMaterial" placeholder="喷头的材质"></el-input>
    </el-form-item>
    <el-form-item label="喷雾方式" prop="sprayMethod">
      <el-input v-model="dataForm.sprayMethod" placeholder="喷雾方式"></el-input>
    </el-form-item>
    <el-form-item label="出液量" prop="dischargeRate">
      <el-input v-model="dataForm.dischargeRate" placeholder="出液量"></el-input>
    </el-form-item>
    <el-form-item label="管长" prop="pipeRange">
      <el-input v-model="dataForm.pipeRange" placeholder="管长"></el-input>
    </el-form-item>
    <el-form-item label="等级，A级。B级" prop="relateLevel">
      <el-input v-model="dataForm.relateLevel" placeholder="等级，A级。B级"></el-input>
    </el-form-item>
    <el-form-item label="图片信息" prop="relateImageInfo">
      <el-input v-model="dataForm.relateImageInfo" placeholder="图片信息"></el-input>
    </el-form-item>
    <el-form-item label="喷雾角度" prop="sprayAngle">
      <el-input v-model="dataForm.sprayAngle" placeholder="喷雾角度"></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="remark">
      <el-input v-model="dataForm.remark" placeholder="备注"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          bottleSprayHeadNo: '',
          spraySize: '',
          sprayHeadDesc: '',
          sprayHeadType: '',
          bottleOutDiameter: '',
          sprayHeadColor: '',
          sprayHeadMaterial: '',
          sprayMethod: '',
          dischargeRate: '',
          pipeRange: '',
          relateLevel: '',
          relateImageInfo: '',
          sprayAngle: '',
          remark: '',
          createUser: '',
          createTime: '',
          updateUser: '',
          updateTime: '',
          parentId: ''
        },
        // dataRule: {
        //   bottleSprayHeadNo: [
        //     { required: true, message: '喷头名称不能为空', trigger: 'blur' }
        //   ],
        //   spraySize: [
        //     { required: true, message: '喷头规格不能为空', trigger: 'blur' }
        //   ],
        //   sprayHeadDesc: [
        //     { required: true, message: '规格描述不能为空', trigger: 'blur' }
        //   ],
        //   sprayHeadType: [
        //     { required: true, message: '喷头类别不能为空', trigger: 'blur' }
        //   ],
        //   bottleOutDiameter: [
        //     { required: true, message: '喷头口径不能为空', trigger: 'blur' }
        //   ]
        // }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/relate/relatesprayheadinfo/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.bottleSprayHeadNo = data.relateSprayHeadInfo.bottleSprayHeadNo
                this.dataForm.spraySize = data.relateSprayHeadInfo.spraySize
                this.dataForm.sprayHeadDesc = data.relateSprayHeadInfo.sprayHeadDesc
                this.dataForm.sprayHeadType = data.relateSprayHeadInfo.sprayHeadType
                this.dataForm.bottleOutDiameter = data.relateSprayHeadInfo.bottleOutDiameter
                this.dataForm.sprayHeadColor = data.relateSprayHeadInfo.sprayHeadColor
                this.dataForm.sprayHeadMaterial = data.relateSprayHeadInfo.sprayHeadMaterial
                this.dataForm.sprayMethod = data.relateSprayHeadInfo.sprayMethod
                this.dataForm.dischargeRate = data.relateSprayHeadInfo.dischargeRate
                this.dataForm.pipeRange = data.relateSprayHeadInfo.pipeRange
                this.dataForm.relateLevel = data.relateSprayHeadInfo.relateLevel
                this.dataForm.relateImageInfo = data.relateSprayHeadInfo.relateImageInfo
                this.dataForm.sprayAngle = data.relateSprayHeadInfo.sprayAngle
                this.dataForm.remark = data.relateSprayHeadInfo.remark
                this.dataForm.createUser = data.relateSprayHeadInfo.createUser
                this.dataForm.createTime = data.relateSprayHeadInfo.createTime
                this.dataForm.updateUser = data.relateSprayHeadInfo.updateUser
                this.dataForm.updateTime = data.relateSprayHeadInfo.updateTime
                this.dataForm.parentId = data.relateSprayHeadInfo.parentId
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/relate/relatesprayheadinfo/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'bottleSprayHeadNo': this.dataForm.bottleSprayHeadNo,
                'spraySize': this.dataForm.spraySize,
                'sprayHeadDesc': this.dataForm.sprayHeadDesc,
                'sprayHeadType': this.dataForm.sprayHeadType,
                'bottleOutDiameter': this.dataForm.bottleOutDiameter,
                'sprayHeadColor': this.dataForm.sprayHeadColor,
                'sprayHeadMaterial': this.dataForm.sprayHeadMaterial,
                'sprayMethod': this.dataForm.sprayMethod,
                'dischargeRate': this.dataForm.dischargeRate,
                'pipeRange': this.dataForm.pipeRange,
                'relateLevel': this.dataForm.relateLevel,
                'relateImageInfo': this.dataForm.relateImageInfo,
                'sprayAngle': this.dataForm.sprayAngle,
                'remark': this.dataForm.remark,
                'createUser': this.dataForm.createUser,
                'createTime': this.dataForm.createTime,
                'updateUser': this.dataForm.updateUser,
                'updateTime': this.dataForm.updateTime,
                'parentId': this.dataForm.parentId
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
